using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Newtonsoft.Json;

namespace ns20
{
	internal static class Class190
	{
		private const string string_0 = "!";

		internal static readonly bool[] bool_0;

		internal static readonly bool[] bool_1;

		internal static readonly bool[] bool_2;

		static Class190()
		{
			bool_0 = new bool[128];
			bool_1 = new bool[128];
			bool_2 = new bool[128];
			IList<char> list = new List<char> { '\n', '\r', '\t', '\\', '\f', '\b' };
			for (int i = 0; i < 32; i++)
			{
				list.Add((char)i);
			}
			foreach (char item in list.Union(new char[1] { '\'' }))
			{
				bool_0[(uint)item] = true;
			}
			foreach (char item2 in list.Union(new char[1] { '"' }))
			{
				bool_1[(uint)item2] = true;
			}
			foreach (char item3 in list.Union(new char[5] { '"', '\'', '<', '>', '&' }))
			{
				bool_2[(uint)item3] = true;
			}
		}

		public static void smethod_0(TextWriter textWriter_0, string string_1, char char_0, bool bool_3, bool[] bool_4, StringEscapeHandling stringEscapeHandling_0, ref char[] char_1)
		{
			if (bool_3)
			{
				textWriter_0.Write(char_0);
			}
			if (string_1 != null)
			{
				int num = 0;
				for (int i = 0; i < string_1.Length; i++)
				{
					char c = string_1[i];
					if (c < bool_4.Length && !bool_4[(uint)c])
					{
						continue;
					}
					string text;
					switch (c)
					{
					case '\\':
						text = "\\\\";
						break;
					case '\b':
						text = "\\b";
						break;
					case '\t':
						text = "\\t";
						break;
					case '\n':
						text = "\\n";
						break;
					case '\f':
						text = "\\f";
						break;
					case '\r':
						text = "\\r";
						break;
					default:
						if (c >= bool_4.Length && stringEscapeHandling_0 != StringEscapeHandling.EscapeNonAscii)
						{
							text = null;
							break;
						}
						if (c == '\'' && stringEscapeHandling_0 != StringEscapeHandling.EscapeHtml)
						{
							text = "\\'";
							break;
						}
						if (c == '"' && stringEscapeHandling_0 != StringEscapeHandling.EscapeHtml)
						{
							text = "\\\"";
							break;
						}
						if (char_1 == null)
						{
							char_1 = new char[6];
						}
						Class199.smethod_8(c, char_1);
						text = "!";
						break;
					case '\u2028':
						text = "\\u2028";
						break;
					case '\u2029':
						text = "\\u2029";
						break;
					case '\u0085':
						text = "\\u0085";
						break;
					}
					if (text == null)
					{
						continue;
					}
					bool flag = string.Equals(text, "!");
					if (i > num)
					{
						int num2 = i - num + (flag ? 6 : 0);
						int num3 = (flag ? 6 : 0);
						if (char_1 == null || char_1.Length < num2)
						{
							char[] array = new char[num2];
							if (flag)
							{
								Array.Copy(char_1, array, 6);
							}
							char_1 = array;
						}
						string_1.CopyTo(num, char_1, num3, num2 - num3);
						textWriter_0.Write(char_1, num3, num2 - num3);
					}
					num = i + 1;
					if (!flag)
					{
						textWriter_0.Write(text);
					}
					else
					{
						textWriter_0.Write(char_1, 0, 6);
					}
				}
				if (num == 0)
				{
					textWriter_0.Write(string_1);
				}
				else
				{
					int num4 = string_1.Length - num;
					if (char_1 == null || char_1.Length < num4)
					{
						char_1 = new char[num4];
					}
					string_1.CopyTo(num, char_1, 0, num4);
					textWriter_0.Write(char_1, 0, num4);
				}
			}
			if (bool_3)
			{
				textWriter_0.Write(char_0);
			}
		}

		public static string smethod_1(string string_1, char char_0, bool bool_3)
		{
			using StringWriter stringWriter = Class199.smethod_6(Class199.smethod_7(string_1) ?? 16);
			char[] char_ = null;
			smethod_0(stringWriter, string_1, char_0, bool_3, (char_0 == '"') ? bool_1 : bool_0, StringEscapeHandling.Default, ref char_);
			return stringWriter.ToString();
		}
	}
}
